package com.example.computer_exam_training_sys.controller;

import com.example.computer_exam_training_sys.entity.User_Examdetails_Info;
import com.example.computer_exam_training_sys.service.User_Examdetails_Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/exam-details")
@CrossOrigin
public class User_Examdetails_Controller {
    @Autowired
    private User_Examdetails_Service examdetailsService;

    // 根据考试ID获取所有答题详情
    @GetMapping("/exam/{exam_id}")
    public List<User_Examdetails_Info> getDetailsByExamId(@PathVariable("exam_id") int exam_id) {
        return examdetailsService.getDetailsByExamId(exam_id);
    }

    // 根据详情ID获取单个答题详情
    @GetMapping("/{detail_id}")
    public User_Examdetails_Info getDetailById(@PathVariable("detail_id") int detail_id) {
        return examdetailsService.getDetailById(detail_id);
    }

    // 新增答题详情
    @PostMapping("/add")
    public int addDetail(@RequestBody User_Examdetails_Info detail) {
        return examdetailsService.addDetail(detail);
    }

    // 根据考试ID和题目ID获取答题详情
    @GetMapping("/exam/{exam_id}/question/{question_id}")
    public User_Examdetails_Info getDetailByExamAndQuestion(
            @PathVariable("exam_id") int exam_id,
            @PathVariable("question_id") int question_id) {
        return examdetailsService.getDetailByExamAndQuestion(exam_id, question_id);
    }
}